package com.samsung.spen.sshare.networking.connection;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.samsung.spen.sshare.R;

import android.R.bool;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class RequestListAdapter extends ArrayAdapter<NetworkAddress> {
	private Context context;
	private int resourceId;
	private ArrayList<NetworkAddress> data;

	public RequestListAdapter(Context context, int textViewResourceId,
			ArrayList<NetworkAddress> files) {

		super(context, textViewResourceId, files);
		this.context = context;
		this.resourceId = textViewResourceId;
		this.data = files;
	}

	@SuppressWarnings("null")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		View row = convertView;
		FileViewHolder holder = null;

		if (convertView == null) {
			LayoutInflater flater = ((Activity) context).getLayoutInflater();
			row = flater.inflate(resourceId, parent, false);

			holder = new FileViewHolder();

			holder.imgIcon = (ImageView) row.findViewById(R.id.itemImageView);
			holder.txtAddress = (TextView) row
					.findViewById(R.id.txtItemAddress);
			holder.txtStatus = (TextView) row.findViewById(R.id.txtItemStatus);

			row.setTag(holder);
		} else
			holder = (FileViewHolder) row.getTag();

		NetworkAddress item = data.get(position);
		int stt = item.getmStatus();
		//TODO set suitable icon for image view
		switch (stt) {
		case NetworkAddress.CONECTING:
			holder.txtStatus.setText("Connecting ...");			
			holder.imgIcon.setImageResource(R.drawable.ic_launcher);
			break;
		case NetworkAddress.CONNECTED:
			holder.txtStatus.setText("Connected");			
			holder.imgIcon.setImageResource(R.drawable.ic_launcher);
			break;
		default:
			break;
		}
		holder.txtAddress.setText(item.getmIp());
		// holder.txtStatus.setText(item.set)
		return row;
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		super.clear();
	}

	static class FileViewHolder {
		ImageView imgIcon;
		TextView txtAddress;
		TextView txtStatus;
	}
}
